<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BUIOperation
 *
 * @author ID59C
 */
class BUIOperation extends BUINode {

    public $views = null;
    public $layoutView = null;
    protected $startScreen = null;
    protected $startScreenFlow = null;

    public function __construct($node = NULL) {
        parent::__construct($node);
        $this->operation = $node;
    }

    public function render($data = null) {

        //before render operation, call doOperation        
        $opp = $this->getActiveOperation();
        $app = $this->getActiveServiceApp();

        parent::render();

        //$this->addRenderView('OperationTopBar', 'operationTopBar', array('uiObj' => $this));

        if ($opp != NULL && $app != NULL) {
            $uiApp = $app->getUIManager();
            $uiApp->setActiveService($this->node->getActiveService());
            $uiApp->renderOperation($opp, $data);
        }

        return FALSE;
    }
    
    public function getName() {
        return $this->operation->getName();
    }

    public function getUrl($data = NULL) {

        $ajaxUrl = $this->getAjaxUrl($data);

        if ($ajaxUrl != NULL)
            return $ajaxUrl;
        
        $serviceId = $this->getActiveService() == NULL ? NULL : $this->getActiveService()->getId();
        $appId = $this->getActiveServiceApp() == NULL ? NULL : $this->getActiveServiceApp()->getId();
        $oppId = $this->getActiveOperation() == NULL ? NULL : $this->getActiveOperation()->getId();

        return $this->buildUrl($serviceId, $appId, $oppId, $data);
    }

    public function getStartScreen() {

        $opMeta = $this->sApp->getAppConfig()->getConfig('opMeta');

        if ($this->startScreen != NULL)
            return $this->getScreen($this->startScreen);

        if (isset($opMeta['startScreen']) && $opMeta['startScreen'] != NULL)
            return $this->getScreen($opMeta['startScreen']);

        return $this->getScreen('BScreenOperation');
    }

    public function getStartScreenFlow() {

        $opMeta = $this->sApp->getAppConfig()->getConfig('opMeta');

        if ($this->startScreenFlow != NULL)
            return $this->getScreenFlow($this->startScreenFlow);

        if (isset($opMeta['startScreen']) && $opMeta['startScreen'] != NULL)
            return $this->getScreenFlow($opMeta['startScreen']);

        return NULL;
    }

    public function setStartScreen($screenName) {
        $this->startScreen = $screenName;
    }

    public function setStartScreenFlow($screenFlowName) {
        $this->startScreenFlow = $screenFlowName;
    }

    public function getActiveServiceApp() {

        if ($this->sApp == NULL) {
            $this->sApp = $this->getOperation()->getActiveServiceApp();
        }
        return $this->sApp;
    }

    public function getOperation() {
        return $this->node;
    }

    public function getViews() {

        if ($this->views == NULL)
            $this->views = array();

        // $this->views['topBar'] = array('view' => 'operationTopBar','uiObj'=>$this);

        return $this->views;
    }

    public function getLayoutView() {
        if ($this->layoutView == NULL)
            $this->layoutView = 'operationLayout2';

        return $this->layoutView;
    }
    
    public function setActiveServiceApp($app) {
        
    }

}

?>
